<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加产品</title>
    <script src="./lib/vue.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="./lib/elementui-index.js"></script>
    <script src="./lib/axios.min.js"></script>
    <script src="./lib/token.js"></script>
</head>
<body>
    <div id="app">
        <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="产品型号">
                <el-input v-model="form.pid" disabled></el-input>
              </el-form-item>
            <el-form-item label="产品型号">
                <el-input v-model="form.ptype" disabled></el-input>
              </el-form-item>
            <el-form-item label="生产工艺">
                <el-input v-model="form.pcraft" disabled></el-input>
            </el-form-item>
            <el-form-item label="产品合同数">
                <el-input v-model="form.pamount" disabled></el-input>
            </el-form-item>
            <el-form-item label="加工面积">
                <el-input v-model="form.parea"></el-input>
            </el-form-item>
            <el-form-item label="加工单价">
                <el-input v-model="form.pprice"></el-input>
            </el-form-item>
            <el-form-item label="加工总金额">
                <el-input v-model="form.pmoney"disabled></el-input>
            </el-form-item>
            <el-form-item label="订单编号">
                <el-input v-model="form.ooid" disabled></el-input>
            </el-form-item>


            <el-form-item>
                <template>
                    <el-button type="primary" @click="open">添加</el-button>
                </template>
              <el-button type="primary" @click="queryOrder">订单查询</el-button>
            </el-form-item>
          </el-form>
    </div>


    <script>
        new Vue({
            el:"#app",
            data() {
                return {
                    form: {
                        pid:'',
                        ptype:"",
                        pcraft:'',
                        pamount:'',
                        psum:'',
                        parea:'',
                        pprice:'',
                        pmoney:'',
                        ooid:'',
                        mid:''
                    },
                }
            },
            methods: {
                updatePlan(){
                    console.log(this.form)
                    axios.put("http://localhost:8001/production/plan/updatePlan",this.form)
                    .then(res=>{
                        console.log(res.data)
                        if(res.data.code === 20000){
                            this.$message.success("添加成功")
                            location.href = "order.html"
                        }else{
                            this.$message.error("添加失败")
                        }
                    })
                },
                open() {
                    this.$confirm('是否添加?', '提示', {
                    confirmButtonText: '添加',
                    cancelButtonText: '取消',
                    type: 'warning'
                    }).then(() => {
                        this.updatePlan()
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消'
                        });        
                    });
                },
                queryOrder(){
                    sessionStorage.ooid = '';
                    location.href = "order.html"
                }
            },
            created(){
                this.form = JSON.parse(sessionStorage.getItem("plan"))
                console.log(this.form)
            }
        })
    </script>
</body>
</html>